home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / basic / apb17.zip / DSEARCH.ASM < prev    next >
Assembly Source File  |  1990-12-20  |  3KB  |  137 lines

  1.     Title Subprogram to do file directory searches
  2.     Page 60,130
  3. ;    Created 10-17-1987 k. murray
  4. ;
  5. Cseg    Segment byte public 'Code'
  6.     Assume Cs:Cseg,Ds:nothing,Es:nothing
  7. ;
  8. ;    Define in program:
  9. ;        Sub FindFirst DirMask$,RetFile$,Er% External "Dsearch.com"
  10. ;        Sub FindNext  RetFile$,Er% External "" 3
  11. ;
  12. Start:
  13.     Jmp    FindFirst
  14.     Jmp    FindNext
  15. ;
  16. ;    Find first file name that matches directory mask
  17. ;    Stack Frame:
  18. ;    Bp+10    Desc. No. of DirMask$
  19. ;    Bp+8    Desc. No. of RetFile$
  20. ;    Bp+6    Adr. of Er%
  21. ;    Bp+4    Return Segment
  22. ;    Bp+2    Return Offset
  23. ;    Bp+0    Saved Bp
  24. FindFirst Proc Far
  25.     Push    Bp
  26.     Mov    Bp,Sp
  27.     Call    SetDta            ; Set DTA to our area
  28.     Mov    Ax,[Bp+10]        ; get DirMask$ string Desc #
  29.     Shl    Ax,1
  30.     Shl    Ax,1
  31.     Mov    Bx,Ax
  32.     Mov    Es,Ds:[6]        ; Segment of string desc's
  33.     Push    Ds
  34.     Mov    Ds,Es:[Bx+2]        ; put segment in Ds
  35.     Mov    Dx,2            ; offset is always 2
  36.     Mov    Bx,Es:[Bx]        ; Put length in Bx
  37.     Push    [Bx+2]            ; Save word after string
  38.     Mov    byte ptr [Bx+2],0    ; put null at end of string
  39.     Push    Bx
  40.     Sub    Cx,Cx            ; Atribute is zero
  41.     Mov    Ah,4eh
  42.     Int    21h            ; do directory search
  43.     Pop    Bx
  44.     Pop    [Bx+2]            ; restore word after name
  45.     Pop    Ds            ; restore data segment
  46.     Jc    FindFirst02        ; error
  47.     Mov    Bx,[Bp+6]
  48.     Sub    Ax,Ax
  49.     Mov    [Bx],Ax            ; Zero error code
  50.     Mov    Ax,[Bp+8]        ; Get desc # of RetFile$
  51.     Call    ReturnName        ; Return the file name
  52.     Sub    Ax,Ax            ; zero return code
  53. FindFirst02:
  54.     Mov    Bx,[Bp+6]        ; Er% adr.
  55.     Mov    [Bx],Ax            ; return erro code
  56.     Pop    Bp
  57.     Ret
  58. FindFirst Endp
  59. ;
  60. ;
  61. ;    Find next matching file name
  62. ;    Stack Frame:
  63. ;    Bp+8    Desc. No. of RetFile$
  64. ;    Bp+6    Adr. of Er%
  65. ;    Bp+4    Return Segment
  66. ;    Bp+2    Return Offset
  67. ;    Bp+0    Saved Bp
  68. FindNext Proc Far
  69.     Push    Bp
  70.     Mov    Bp,Sp
  71.     Call    SetDta            ; Set DTA to our area
  72.     Mov    Ah,4fh
  73.     Int    21h            ; Search for next file
  74.     Jc    FindNext02        ; error
  75.     Mov    Ax,[Bp+8]        ; Desc # of RetFile$
  76.     Call    ReturnName        ; return the file name
  77.     Sub    Ax,Ax
  78. FindNext02:    
  79.     Mov    Bx,[Bp+6]
  80.     Mov    [Bx],Ax            ; save error code
  81.     Pop    Bp
  82.     Ret
  83. FindNext Endp
  84. ;
  85. ;
  86. ;;    Set DTA to our file structure
  87. SetDta:
  88.     Push    Ds
  89.     Mov    Ax,Cs
  90.     Mov    Ds,Ax
  91.     Lea    Dx,FileStruc
  92.     Mov    Ah,1ah
  93.     Int    21h            ; Set DTA
  94.     Pop    Ds
  95.     Ret
  96. ;
  97. ;
  98. ;;    Return the file name to string desc # in Ax
  99. ReturnName:
  100.     Shl    Ax,1
  101.     Shl    Ax,1            ; Mult by 4
  102.     Mov    Bx,Ax
  103.     Mov    Es,Ds:[6]        ; Desc segment in Es
  104.     Mov    Cx,Es:[Bx]        ; get current length in Cx
  105.     Mov    Es,Es:[Bx+2]        ; put string's segment in Es
  106.     Jcxz    ReturnNameEnd        ; string has no length
  107.     Push    Cx            ; save length
  108.     Mov    Di,2            ; offset of string
  109.     Cld
  110.     Mov    Al,' '
  111.     Rep    Stosb            ; fill string with spaces
  112.     Lea    Si,FName        ; Si=adr. of file name
  113.     Mov    Di,2            ; adr. to put file name
  114.     Pop    Cx            ; restore string's original length
  115. ReturnName02:
  116.     Mov    Al,Cs:[Si]
  117.     Inc    Si
  118.     Or    Al,Al
  119.     Jz    ReturnNameEnd        ; end of file name
  120.     Stosb                ; save character
  121.     Loop    ReturnName02        ; loop until end of name or out of space
  122. ReturnNameEnd:
  123.     Ret
  124. ;
  125. ;    Data goes here
  126. ;
  127. FileStruc label byte
  128. Reserved Db 21 dup (0)        ; Reserved by DOS
  129. Atrib    Db    0        ; Atribute of the file
  130. FTime    Dw    0        ; Last time file was modified
  131. FDate    Dw    0        ; Last date file was modified
  132. FSize    Dd    0        ; Long word of file size
  133. FName    Db    13 dup (0)    ; Actual file name
  134. ;
  135. Cseg    Ends
  136.     End    Start
  137.